<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input class="inp" type="text">
</body>
<script>
    var inp = document.getElementsByClassName("inp")[0];

    let data = {};

    // data.val  的取值和赋值依赖于  inp.value
    Object.defineProperty(data, "val", {
        get: function () {  // data.val => inp.value
            return inp.value;
        },
        set: function (val) {// data.val = xxx;   inp.value = val;
            inp.value = val;
        },
        enumerable: true,
        configurable: true,
    })

    inp.oninput = function () {
        console.log(data.val);
    }













</script>

</html>